|
|
|
|
|
|
|
record and change the CustType column value from T01 to T09. After you finish the edit and move the record pointer to another record in the ValidTypes grid, click the Refresh button to update both datasets. You see that all records in the MasterTable that had a value of T01 in their CustType field now have a value of T09. The update of ValidTypes was cascaded into the MasterTable by Microsoft Jet. |
|
|
|
|
|
|
|
|
Now add a new record with the CustType value of T99 to the ValidTypes table (set the Description field to any text you want). Add a record to the MasterTable that uses the T99 value in its CustType field. Your screen should look something like the one shown in Figure 17.9. |
|
|
|
|
|
|
|
|
Figure 17.9.
Adding new records to the MULTIUSE.MDB database. |
|
|
|
|
|
|
|
|
Delete the T99 record from the ValidTypes table by highlighting the entire row and pressing Delete. After you delete the record, click the Refresh button again to update both data controls. What happens to the record in the MasterTable that contains the T99 value in the CustType field? It is deleted from the MasterTable! This shows the power of the cascading delete. When cascading deletes are enforced, any time a user deletes a record from the base table, all related records in the foreign table also are deleted. |
|
|
|
|
|
|
|
|
When to Use the Cascading Updates and Deletes |
|
|
|
|
|
|
|
|
The capability to enforce cascading updates and deletes as part of the database definition is a powerful tool. With this power comes some responsibility, too, however. Because database cascades cannot easily be undone, you should think through your database design carefully before you add cascading features to your database. It is not always wise to add both update and delete cascades to all your relationships. At times, you might not want to cascade all update or delete operations. |
|
|
|
|
|
|
|
|
Whenever you define a relation object in which the base table is a validation table and the foreign table is a master table, it is wise to define an update cascade. This ensures that any changes made to the validation table are cascaded to the related master table. It is not a good idea to define a delete cascade for this type of relation. Rarely do you want to delete all master |
|
|
|
|
|